package com.mujin.keji.collectionsystem.module.outboundtask.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.UserBean;
import com.mujin.keji.collectionsystem.widget.SelectAssistCommissionerWindow;

import java.util.List;


/**
 * 选择外访专员
 *
 * @author weishixiong
 * @Time 2018-05-12
 */
public class SelectAssistCommissionerAdapter extends RecyclerView.Adapter<SelectAssistCommissionerAdapter.ViewHolder> {
    private Context mContext;
    private List<UserBean> datas;
    private CustomItemClickListener listener;
    private SelectAssistCommissionerWindow selectAssistCommissionerWindow;

    public SelectAssistCommissionerAdapter(Context context, List<UserBean> datas, CustomItemClickListener listener, SelectAssistCommissionerWindow selectAssistCommissionerWindow) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
        this.selectAssistCommissionerWindow = selectAssistCommissionerWindow;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_assistcommissioner, null, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tvName.setText(datas.get(position).getUserName());
        holder.tvName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onItemClick(holder.tvName, position);
                selectAssistCommissionerWindow.dismiss();
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private TextView tvName;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);

        }

        @Override
        public void onClick(View v) {

        }
    }
}
